package com.dubboservice.demos.controller;


import com.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.example.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Lenovo
 * DATA:2024/8/25
 **/
@RestController
@RequestMapping("/user")
public class UserController {


    /**
     * @DubboReference
     * 从 zookeeper 注册中心获取userService 访问的 url
     * 进行远程调用 RPC
     * 将结果封装为一个代理对象，给变量赋值
     */
    @DubboReference
    private UserService userService;

    @RequestMapping("/sayHello")
    public String sayHello(){
        return userService.sayHello();
    }

    /**
     * 根据id 查询用户信息
     * @param id
     * @return
     */
    @RequestMapping("/getUser")
    public User findByUser(int id){
        return userService.findByUser(id);
    }
}
